From c9f0f4263eede1e1d986a0131c8b296ce72c593a Mon Sep 17 00:00:00 2001 From: Jyrki Gadinger Date: Tue, 15 Apr 2025 10:13:14 +0200 Subject: [PATCH] fix(theme): correct dark/light mode check on Win10 `Utility::registryGetKeyValue` returns an invalid QVariant should the key not exist -- which is the case if that switch has never been toggled before. --> Fix this by ensuring the QVariant is valid, and only then try to convert it to a bool. Signed-off-by: Jyrki Gadinger --- src/libsync/theme.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 9e90a0002..f1a7108bd 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -1032,10 +1032,11 @@ bool Theme::darkMode() const #ifdef Q_OS_WIN static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); - if (!isWindows11OrGreater() && - Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) && - !Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) { - return true; + if (!isWindows11OrGreater() && Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey)) { + if (const auto keyVariant = Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")); + keyVariant.isValid() && !keyVariant.toBool()) { + return true; + } } #endif return isDarkFromStyle(); -- 2.30.2